<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="s" uri="/struts-tags" %>

<script type="text/javascript" src="js/jquery.itextclear.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
        $('input[type=text], input[type=password], input[type=url], input[type=email], input[type=number], textarea', '.form').iTextClear();
    });
</script>
<!-- jQplot CSS -->

<link rel="stylesheet" media="screen" href="${ctx}/css/Tree.css"/>
<link rel="stylesheet" media="screen" href="${ctx}/css/docs.css"/>
<!-- jQplot CSS END -->

<!-- DATATABLES CSS -->
<link rel="stylesheet" media="screen" href="lib/datatables/css/vpad.css"/>
<script type="text/javascript" src="lib/datatables/js/jquery.dataTables.js"></script>
<script type="text/javascript" src="${ctx}/js/global_util.js"></script>
<!-- DATATABLES CSS END -->


<h1 class="page-title">合同签订审核-审核</h1>


<div class="container_12 clearfix leading">
    <section class="tabs grid_12 leading">
        <ul class="clearfix">
            <s:iterator value="#request.signPojo2.versions" var="v" status="sta">
                <li><a href="#" onclick="changeTab('${v.id}')">${v.contractName}</a></li>
            </s:iterator>
        </ul>
        <section>

            <DIV class="portlet">
                <header>
                    <h5_n>${signPojo2.work.baseId.name}</h5_n>
                    <h2><s:if test="#request.signPojo2.work.baseId.sex==0">先生</s:if><s:else>女士</s:else></h2>
                </header>
                <section class="clearfix">
                    <div class="grid_2 alpha" style=" text-align:center">
                        <s:if test="#request.signPojo2.work.baseId.facePath==null || #request.signPojo2.work.baseId.facePath.equals(\"\")">
                            <img width="120" height="135" src="images/Avatar.jpg" id="image_upload">
                        </s:if>
                        <s:else>
                            <img width="120" height="135" src="${signPojo2.work.baseId.facePath}" id="image_upload">
                        </s:else>
                    </div>
                    <div class="grid_3">
                        <dl>
                            <dt>岗位</dt>
                            <dd><h6>${signPojo2.work.duty.dutyName}</h6></dd>
                            <dt>员工号</dt>
                            <dd><h6>${signPojo2.work.workNo}</h6></dd>
                            <dt>职等</dt>
                            <dd><h6>${signPojo2.work.grade.gradeName}</h6></dd>
                        </dl>
                    </div>
                    <div class="grid_3">
                        <dl>
                            <dt>部门</dt>
                            <dd><h6>${signPojo2.work.organization.fullName}</h6></dd>
                            <dt>职务</dt>
                            <dd><h6>${signPojo2.work.duty.dutyName} </h6></dd>
                            <dt>职级</dt>
                            <dd><h6>${signPojo2.work.gradeLevel.gradeSort}</h6></dd>
                        </dl>
                    </div>
                </section>
            </DIV>

            <s:iterator value="#request.signPojo2.versions" var="v" status="sta">
                <section class="clearfix" style="display: block;">
                    <DIV class="portlet" style="padding-top:15px">
                        <header>
                            <h5_n>${v.contractName}
                                <s:if test="#request.v.sign == null and #request.v.signZz == null and #request.v.signRt == null and #request.v.signRtt == null">
                                    <a style=" float:right" class="button" href="#contract/sign_create.xhtml?baseId=${signPojo2.work.baseId.id}&did=${signPojo2.work.duty.id}&version.id=${v.id}">
                                        <span class="icon" style="background:url(${ctx}/images/img/page_add.png)">&nbsp;</span>生成合同
                                    </a>
                                </s:if>  
                                <s:elseif test="(#request.v.sign != null and #request.v.sign.auditStatus.toString() == 'wait_audit' and #request.v.sign.state==1) or (#request.v.signZz != null and #request.v.signZz.auditStatus.toString() == 'wait_audit' and #request.v.signZz.state==1) or (#request.v.signRt != null and #request.v.signRt.auditStatus.toString() == 'wait_audit') or (#request.v.signRtt != null and #request.v.signRtt.auditStatus.toString() == 'wait_audit')">
                                   
                                    <s:if test="#request.v.contractTemplate=='contract_template1'">
                                        <a style=" float:right; margin-left:15px" class="button" href="#contract/sign_create.xhtml?contractSign.id=${v.sign.id}&version.id=${v.id}&did=${signPojo2.work.duty.id}">
                                            <span class="icon" style="background:url(${ctx}/images/img/page_edit.png)">&nbsp;</span>修改合同
                                        </a>
                                    </s:if>
                                    <s:elseif test="#request.v.contractTemplate=='contract_template3'">
                                    	<a style=" float:right; margin-left:15px" class="button" href="#contract/sign_create.xhtml?contractSignRt.id=${v.signRt.id}&version.id=${v.id}&did=${signPojo2.work.duty.id}">
                                            <span class="icon" style="background:url(${ctx}/images/img/page_edit.png)">&nbsp;</span>修改合同
                                        </a>
                                    </s:elseif>
                                    <s:elseif test="#request.v.contractTemplate=='contract_template4'">
                                    	<a style=" float:right; margin-left:15px" class="button" href="#contract/sign_create.xhtml?contractSignRtt.id=${v.signRtt.id}&version.id=${v.id}&did=${signPojo2.work.duty.id}">
                                            <span class="icon" style="background:url(${ctx}/images/img/page_edit.png)">&nbsp;</span>修改合同
                                        </a>
                                    </s:elseif>
                                    <s:else>
                                        <a style=" float:right; margin-left:15px" class="button" href="#contract/sign_create.xhtml?contractSignZz.id=${v.signZz.id}&version.id=${v.id}&did=${signPojo2.work.duty.id}">
                                            <span class="icon" style="background:url(${ctx}/images/img/page_edit.png)">&nbsp;</span>修改合同
                                        </a>
                                    </s:else>
                                </s:elseif>
                                <s:elseif test="(#request.v.sign != null and #request.v.sign.auditStatus.toString() == 'pass_audit') or (#request.v.signZz != null and #request.v.signZz.auditStatus.toString() == 'pass_audit') or (#request.v.signRt != null and #request.v.signRt.auditStatus.toString() == 'pass_audit') or (#request.v.signRtt != null and #request.v.signRtt.auditStatus.toString() == 'pass_audit')">
                                    <s:if test="#request.v.contractTemplate=='contract_template1'">
                                        <a style=" float:right; margin-left:15px" class="button" href="#contract/generateContractdoc.xhtml?sign.id=${v.sign.id}">
                                            <span class="icon" style="background:url(${ctx}/images/img/page_edit.png)">&nbsp;</span> 生成word合同
                                        </a>
                                    </s:if>
                                    <s:elseif test="#request.v.contractTemplate=='contract_template3'">
                                    	<a style=" float:right; margin-left:15px" class="button" href="#contract/generateContractdoc.xhtml?signRt.id=${v.signRt.id}">
                                            <span class="icon" style="background:url(${ctx}/images/img/page_edit.png)">&nbsp;</span>生成word合同
                                        </a>
                                    </s:elseif>
                                    <s:elseif test="#request.v.contractTemplate=='contract_template4'">
                                    	<a style=" float:right; margin-left:15px" class="button" href="#contract/generateContractdoc.xhtml?signRtt.id=${v.signRtt.id}">
                                            <span class="icon" style="background:url(${ctx}/images/img/page_edit.png)">&nbsp;</span>生成word合同
                                        </a>
                                    </s:elseif>
                                    <s:else>
                                        <a style=" float:right; margin-left:15px" class="button" href="#contract/generateContractdoc.xhtml?signZz.id=${v.signZz.id}">
                                            <span class="icon" style="background:url(${ctx}/images/img/page_edit.png)">&nbsp;</span>生成word合同
                                        </a>
                                    </s:else>
                                </s:elseif>

                                <s:if test="(#request.v.sign != null and #request.v.sign.auditStatus.toString() == 'pass_audit' and #request.v.sign.state==5) or (#request.v.signZz != null and #request.v.signZz.auditStatus.toString() == 'pass_audit' and #request.v.signZz.state==5) or (#request.v.signRt != null and #request.v.signRt.auditStatus.toString() == 'pass_audit' and #request.v.signRt.state==5) or (#request.v.signRtt != null and #request.v.signRtt.auditStatus.toString() == 'pass_audit' and #request.v.signRtt.state==5)">
                                    <s:if test="#request.v.contractTemplate=='contract_template1'">
                                        <a style=" float:right; margin-left:15px" class="button" href="#contract/sign_create.xhtml?reSignContractSignId=${v.sign.id}&baseId=${signPojo2.work.baseId.id}&did=${signPojo2.work.duty.id}&version.id=${v.id}">
                                            <span class="icon" style="background:url(${ctx}/images/img/page_edit.png)">&nbsp;</span> 续签合同
                                        </a>
                                    </s:if>
                                    <s:elseif test="#request.v.contractTemplate=='contract_template3'">
                                    	<a style=" float:right; margin-left:15px" class="button" href="#contract/sign_create.xhtml?reSignContractSignRtId=${v.signRt.id}&baseId=${signPojo2.work.baseId.id}&did=${signPojo2.work.duty.id}&version.id=${v.id}">
                                            <span class="icon" style="background:url(${ctx}/images/img/page_edit.png)">&nbsp;</span>续签合同
                                        </a>
                                    </s:elseif>
                                    <s:elseif test="#request.v.contractTemplate=='contract_template4'">
                                    	<a style=" float:right; margin-left:15px" class="button" href="#contract/sign_create.xhtml?reSignContractSignRttId=${v.signRtt.id}&baseId=${signPojo2.work.baseId.id}&did=${signPojo2.work.duty.id}&version.id=${v.id}">
                                            <span class="icon" style="background:url(${ctx}/images/img/page_edit.png)">&nbsp;</span>续签合同
                                        </a>
                                    </s:elseif>
                                    <s:else>
                                        <a style=" float:right; margin-left:15px" class="button" href="#contract/sign_create.xhtml?reSignContractSignZzId=${v.signZz.id}&baseId=${signPojo2.work.baseId.id}&did=${signPojo2.work.duty.id}&version.id=${v.id}">
                                            <span class="icon" style="background:url(${ctx}/images/img/page_edit.png)">&nbsp;</span>续签合同
                                        </a>
                                    </s:else>
                                </s:if>
                            </h5_n>
                            <h2>版本：${v.contractVer}</h2>
                        </header>
                        <section class="clearfix contract_template" contract_path="${v.contractTemplate}" contract_id="${v.id}" contract_status="${v.status}" sign_id="${v.sign.id}" sign_zz_id="${v.signZz.id}" sign_rt_id="${v.signRt.id}" sign_rtt_id="${v.signRtt.id}">
                            <%--${v.contractName} 合同详细(include合同模板)--%>
                            <div id="contract_template_${v.id}" ></div>

                            <div class="clear"></div>

                        </section>
                    </DIV>
                </section>
            </s:iterator>
        </section>
    </section>

    <div class="tabs side grid_12 leading">

        <div class="clear"></div>
    </div>

</div>


<%--审核--%>
<%--<%@ include file="/WEB-INF/pages/common/common_audit.jsp" %>--%>
<div class="clear"></div>
<%--审核信息--%>
<s:iterator value="#request.signPojo2.versions" var="v" status="sta">
<div id="contract_audit_${v.id}" style="display: none;" class="audit_div">
    <s:if test="#request.v.sign == null and #request.v.signZz == null and #request.v.signRt == null and #request.v.signRtt == null"></s:if>
    <s:else>
        <hr/>
        <div class="container_12 clearfix leading">
            <div class="tabs side grid_6">
                <h5>历史审核</h5>
                <ul class="clearfix">
                    <s:if test="#request.v.audits != null and #request.v.audits.size() > 1">
                        <s:iterator value="#request.v.audits" status="sta">
                            <s:if test="#request.sta.index < #request.v.audits.size() - 1">
                                <li><a class="current" href="#">历史审核#<s:property value="#request.sta.index+1"/></a></li>
                            </s:if>
                        </s:iterator>
                    </s:if>
                    <s:else>
                        <li><a class="current" href="#">没有历史记录</a></li>
                    </s:else>
                </ul>
                <section>
                    <s:if test="#request.v.audits != null and #request.v.audits.size() > 1">
                        <s:iterator value="#request.v.audits" var="audit_process" status="sta">
                            <s:if test="#request.sta.index < #request.v.audits.size() - 1">
                                <section style="display: block;" class="clearfix ehr_log">
                                        <%--<h4>2012年3月22日</h4>--%>
                                    <div class="grid_12 alpha">
                                        <hr>
                                        <ol class="nostyle">
                                            <s:iterator value="#request.audit_process" var="a">
                                                <li>
                                                    <p class="title"> ${a.auditing.auditTag}
                                                        <button type="reset" class="button" style="float: right">
                                                            <span style="background:url(${ctx}/images/img/accept.png)" class="icon">&nbsp;</span>${a.status.name}
                                                        </button>
                                                    </p>
                                                    <p>${a.auditContent}</p>
                                                </li>
                                            </s:iterator>
                                        </ol>
                                    </div>
                                </section>
                            </s:if>
                        </s:iterator>
                    </s:if>
                    <s:else>
                        <section style="display: none;" class="clearfix">
                            <div class="grid_12 alpha">没有历史审核记录</div>
                        </section>
                    </s:else>
                </section>
            </div>

            <div class="side grid_6">
                <h5>当前审核</h5>
                <div class="accordion">
                    <s:if test="#request.v.audits != null and #request.v.audits.size() > 0">
                        <s:iterator value="#request.v.audits" var="current_audit_process" status="sta">
                            <s:if test="#request.sta.index == #request.v.audits.size() - 1">
                                <s:iterator value="#request.current_audit_process" var="ad" status="sta4">

                                    <!-- 审核已通过 -->
                                    <s:if test="#request.ad.status.toString() == 'pass_audit'">
                                        <header class="current">
                                            <h2> ${ad.auditing.auditTag}
                                                <button type="reset" class="button" style="margin-left: 250px;">
                                                    <span style="background:url(${ctx}/images/img/accept.png)" class="icon">&nbsp;</span>已审核
                                                </button>
                                            </h2>
                                        </header>
                                        <section class="clearfix" style="display: block;">${ad.auditContent}</section>
                                    </s:if>
                                    <!--未审核-->
                                    <s:elseif test="#request.ad.status.toString() == 'wait_audit'">
                                        <%--TODO:由当前登录用户来审核(这里判断当前登录用户是否可审核)--%>
                                        <s:if test="#request.sta4.index == -1 or 1==1">
                                            <header>
                                                <h2>${ad.auditing.auditTag}</h2>
                                            </header>
                                            <section class="clearfix">
                                                <h6 style="display: none;">待审核</h6>
                                                <div class="audit_selection_div_${v.id}" id="audit_selection_div_${ad.id}">
                                                    <s:if test="#request.v.canAudit == false">
                                                        <h6>非当前审核者</h6>
                                                    </s:if>
                                                    <s:else>
                                                        <h6>审核意见</h6>
                                                        <hr>
                                                        <textarea rows="5" style="width: 100%; margin-bottom: 10px;" id="audit_content_${v.id}"></textarea>
                                                        <input type="radio" name="audit_radio_${v.id}" value="pass_audit"> 同意
                                                        <input type="radio" name="audit_radio_${v.id}" value="reject_audit"> 不同意
                                                        <button class="button" type="button" onclick="doAudit(${v.id})">
                                                            <input type="hidden" value="${ad.id}" id="audit_id_${v.id}">
                                                            <span class="icon" style="background:url(${ctx}/images/img/help.png)">&nbsp;</span>确定审核
                                                        </button>
                                                    </s:else>
                                                </div>
                                            </section>
                                        </s:if>
                                        <s:else>
                                            <header>
                                                <h2> ${ad.auditing.auditTag}
                                                    <button type="reset" class="button" style="margin-left: 250px;">
                                                        <span style="background:url(${ctx}/images/img/information.png)" class="icon">&nbsp;</span>未审核
                                                    </button>
                                                </h2>
                                            </header>
                                            <section class="clearfix"></section>
                                        </s:else>
                                    </s:elseif>

                                </s:iterator>
                            </s:if>
                        </s:iterator>
                    </s:if>
                    <s:else>
                        <header>
                            <h2>&nbsp;没有添加审核配置</h2>
                        </header>
                        <section class="clearfix">&nbsp;</section>
                    </s:else>
                </div>
            </div>
        </div>
        <div class="clear"></div>
        <div style="margin-left: 20px;">
            <s:if test="#request.v.sign != null and #request.v.sign.state==3">
                <a style="margin-left:15px" class="button" href="javascript:void(0)" onclick="sign(${v.sign.id}, 'sign')">
                    <span class="icon" style="background:url(${ctx}/images/img/page_edit.png)">&nbsp;</span> 签订合同
                </a>
            </s:if>
            <s:elseif test="#request.v.signZz != null and #request.v.signZz.state==3">
                <a style="margin-left:15px" class="button" href="javascript:void(0)" onclick="sign(${v.signZz.id}, 'signZz')">
                    <span class="icon" style="background:url(${ctx}/images/img/page_edit.png)">&nbsp;</span> 签订合同
                </a>
            </s:elseif>
            <s:elseif test="#request.v.signRt != null and #request.v.signRt.state==3">
                <a style="margin-left:15px" class="button" href="javascript:void(0)" onclick="sign(${v.signRt.id}, 'signZz')">
                    <span class="icon" style="background:url(${ctx}/images/img/page_edit.png)">&nbsp;</span> 签订合同
                </a>
            </s:elseif>
            <s:elseif test="#request.v.signRtt != null and #request.v.signRtt.state==3">
                <a style="margin-left:15px" class="button" href="javascript:void(0)" onclick="sign(${v.signRtt.id}, 'signZz')">
                    <span class="icon" style="background:url(${ctx}/images/img/page_edit.png)">&nbsp;</span> 签订合同
                </a>
            </s:elseif>
        </div>
    </s:else>
</div>
</s:iterator>

<script type="text/javascript" src="js/Tree.js"></script>
<!-- POPOVER SETUP--><script type="text/javascript" src="js/Tree.js"></script>
<script type="text/javascript">
    $(function() {
        var i=0;
        $("section.contract_template").each(function() {
            var contractTemplate = $(this).attr("contract_path");
            var versionId = $(this).attr("contract_id");
            var employId = "${signPojo2.work.baseId}";

            var data = {"employId":"${signPojo2.work.baseId.id}", "contract_template":contractTemplate + ".jsp", "versionId":versionId}; //contract_template1.jsp
            //alert(data.contract_template)
            var url = "${ctx}/contract/contract_template.xhtml";
            $.ajax(url, {
                type: "POST",
                data:data,
                dataType:"html",
                cache:false,
                success:function(a) {
                    var obj = $("#contract_template_" + versionId);
                    obj.html("");
                    obj.append(a);
                },
                complete:function() {
                }
            });

            if(i == 0){
                changeTab(versionId);
                i++;
            }
        });

        //setTimeout("init()", 1000)
    });
    function changeTab(vid){
        $(".audit_div").each(function(){
            $(this).hide();
        });

        var obj = $("#contract_audit_"+vid);
        if(obj != null){
            $(obj).show();
        }
    }

    function sign(sid, type){
        var url = null;
        if(type == 'sign'){
            url = "${ctx}/ajax/contact_sign.xhtml?contractSign.id="+sid
        }else if(type == 'signZz'){
            url = "${ctx}/ajax/contact_signZz.xhtml?contractSignZz.id="+sid;
        }else if(type == 'signRt'){
            url = "${ctx}/ajax/contact_signRt.xhtml?contractSignRt.id="+sid;
        }else if(type == 'signRtt'){
            url = "${ctx}/ajax/contact_signRtt.xhtml?contractSignRtt.id="+sid;
        }
        if(url == null){
            return;
        }

        $.ajax(url, {
            type: "POST",
            dataType:"json",
            cache:false,
            success:function(a) {
                if(a == true){
                    alert("签订成功")
                    window.location.href = "#contract/conAudit.xhtml";
                }
            },
            complete:function() {
            }
        });
    }

    //审核相关=============================
    $(function() {
        $("section.contract_template").each(function() {
            var versionId = $(this).attr("contract_id");
            //设置当前审核
            $("div.audit_selection_div_"+versionId).each(function(i) {
                if (i != 0) {
                    $(this).prev("h6").show();
                    $(this).hide();
                }
            });
        });
    });
    function doAudit(vid) {
        var content = $("#audit_content_"+vid).val();
        if (checkNull(content)) {
            return;
        }
        //var auditStatus = $("input[type='radio'][@name='audit_radio'][checked]").val();
        var auditStatus = "";
        $("input[type='radio'][name='audit_radio_"+vid+"']").each(function() {
            if ($(this).parent(".checked").length == 1) {
                auditStatus = $(this).val();
                return false; //退出each(相当于break, return true相当于continue)
            }
        });

        var auditId = $("#audit_id_"+vid).val();
        if (auditId == "") {
            return;
        }

        if (auditStatus == null || auditStatus.length == "") {
            //alert("auditStatus="+auditStatus)
            return;
        }

        //构造一个通用的AuditBase对象
        var data = {
            "auditing.id":auditId,
            "organizationId":"${organizationId}",
            "currentAuditType":"${currentAuditType}",
            "auditing.status":auditStatus,
            "auditing.auditContent":content,
            "currentAuditAction": "/contract/conAudit.xhtml"
        };

        //for(var p in data){alert(p+"----"+data[p])}
        refreshMainContent("${ctx}/authority/audit-base.xhtml", data);
    }
</script>